*HS graduation status
*This program does a basic cleanup on the state level SIMS files for getting HS graduation info
*Base "on-time" HS graduation on application to charter year

***************************************
********** SET UP STATA ***************
***************************************
set more off
clear
global sims "$raw\SIMS"
global saves "$raw\saves"


*********************************************************
********** FORMAT HIGH SCHOOL ENROLLMENT FILES **********
*********************************************************


		*Extract info from high school enrollment files
		local l=1
		foreach y in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 {
			foreach t in eoy oct {
				cap use "$sims\sims`t'`y'.dta", clear
				if _rc==0 {
					cap rename *, lower
					keep sasid grade enstat
					gen t=`l'
					gen period="`t'"
					gen year=20`y'
					****NOTE FOR CHARTER KEEP GRADES ABOVE 4
					keep if grade=="04" |grade=="05" |grade=="06" |grade=="07" |grade=="08" | ///
						grade=="09" | grade=="10" | grade=="11" | grade=="12"
					destring sasid grade, replace force
					duplicates drop
					save "$saves\high_`t'`y'.dta", replace
					local ++l
				}			
			
			}
		}
			


	**Keep earliest time period in SIMS for each student
		use "$saves\high_eoy02.dta", clear
		foreach y in 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19  20 21 22 23 {
			foreach t in eoy oct {
				cap append using "$saves\high_`t'`y'.dta"
				
			}
		}		
		duplicates drop
		save "$data_clean\full_hs_file.dta", replace
		
